import { ProTableColumn } from '@/components/pro-table/type'
import { NButton, NPopconfirm } from 'naive-ui'
import { InventoryModel } from '@/api/model/inventory-model'

type Props = {
  type: string
  fetchInventory: (row: any, status: string) => void
}

export const useInventoryProTable = ({ type, fetchInventory }: Props) => {
  const { typeOptions, typeLoading } = useGetTypeList()
  const columns = computed<ProTableColumn<InventoryModel>[]>(() => {
    return [
      // {
      //   title: '盘点编号',
      //   key: 'inventoryCode'
      // },
      // {
      //   title: '盘点名称',
      //   key: 'inventoryName'
      // },
      {
        title: '资产名称',
        key: 'assetName'
      },
      {
        title: '资产编码',
        key: 'assetCode'
      },
      {
        type: 'dict',
        title: '资产类型',
        key: 'typeId',
        dictOptions: typeOptions.value
      },
      {
        title: '所属部门',
        key: 'branchName'
      },
      {
        title: '品牌',
        key: 'brand'
      },
      {
        title: '规格型号',
        key: 'model'
      },
      {
        type: 'tag',
        title: '资产盘点状态',
        key: 'inventoryAssetStatus',
        dictCode: 'INVENTORY_DETAILS_TYPE'
      },
      {
        title: '操作',
        key: 'operation',
        render(row) {
          return (
            <>
              {row.inventoryAssetStatus === '0' && type !== 'detail' ? (
                <NButton
                  type="primary"
                  size="small"
                  onClick={() => fetchInventory(row, '3')}
                  quaternary
                >
                  盘点
                </NButton>
              ) : (
                ''
              )}

              {row.inventoryAssetStatus === '0' && type !== 'detail' ? (
                <NPopconfirm onPositiveClick={() => fetchInventory(row, '1')}>
                  {{
                    trigger: () => (
                      <NButton size="small" type="error" quaternary>
                        盘亏
                      </NButton>
                    ),
                    default: () => '您确定要盘亏？'
                  }}
                </NPopconfirm>
              ) : (
                ''
              )}

              {row.inventoryAssetStatus === '0' && type !== 'detail' ? (
                <NPopconfirm onPositiveClick={() => fetchInventory(row, '2')}>
                  {{
                    trigger: () => (
                      <NButton type="success" size="small" quaternary>
                        盘盈
                      </NButton>
                    ),
                    default: () => '您确定要盘盈？'
                  }}
                </NPopconfirm>
              ) : (
                ''
              )}
            </>
          )
        }
      }
    ]
  })
  return {
    columns
  }
}
